package org.springleaf.security.service.impl;

import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springleaf.security.model.User;
import org.springleaf.utils.SpringBeanFactoryUtils;

import app.demo.service.CustomerService;

/**
 * 自定义的用户清单服务
 * @author leaf
 */
public class UserDeatilServiceImpl implements UserDetailsService{
	
	private CustomerService userService;
	
	@Override
	public UserDetails loadUserByUsername(String userName)
			throws UsernameNotFoundException, DataAccessException {
		User u = getUserService().getUserByUsername(userName);
		return u;
	}
	
	private CustomerService getUserService(){
		if(this.userService == null)
			this.userService = SpringBeanFactoryUtils.getBean("customerService");
		return this.userService;
	}

}
